//
//  BaseFormViewController.swift
//  MT
//
//  Created by ooops on 2019/12/26.
//  Copyright © 2019 张强. All rights reserved.
//

import UIKit
import YPNavigationBarTransition
import Eureka
import MTCategory

public class BaseFormViewController: FormViewController, RefreshView {
    
    override public var customNavigationAccessoryView: (UIView & NavigationAccessory)? {
        
        let accessoryView = MTCustomFromAccessoryView()
        accessoryView.doneClosure = { [weak self] in
            self?.tableView?.endEditing(true)
        }
        
        return accessoryView
    }
    
    
    /// 某些特殊情况下使用的导航控制器. 有一定风险, 保证获取的导航控制器上没有 present 出来的控制器, 具体使用结合情况
    lazy var navigationVC: BaseNavController? = {
        let nav: BaseNavController = (UIApplication.mt_keyWindow?.rootViewController as! BaseTabBarViewController).selectedViewController as! BaseNavController
        return nav
    }()
    
    lazy var noDataView : NoDataView = {
        return NoDataView.defaultNoDataView()
    }()
    
    func noDataView(hide: Bool) {
        if hide{
            
            noDataView.removeFromSuperview()
            
        }else{
            self.view.addSubview(noDataView)
            noDataView.snp.makeConstraints({ (make) in
                make.edges.equalTo(self.view)
            })
        }
    }
    
    open func refreshView(){
        
    }

    override public func viewDidLoad() {
        super.viewDidLoad()
        extendedLayoutIncludesOpaqueBars = true
        self.navigationController?.navigationBar.titleTextAttributes = [NSAttributedString.Key.foregroundColor:UIColor.text.x1d1a1a, NSAttributedString.Key.font:PingFangSCSemiboldFont(16)]
        view.backgroundColor = UIColor.theme.background
        backButton()
    }
        
    open override var preferredStatusBarStyle: UIStatusBarStyle {
        return .default
    }

}



extension BaseFormViewController: NavigationBarConfigureStyle {
    open func yp_navigationBarTintColor() -> UIColor! {
        return UIColor(hex: 0x000000)
    }

    open func yp_navigtionBarConfiguration() -> YPNavigationBarConfigurations {
        return [.backgroundStyleColor, .styleBlack, .backgroundStyleOpaque]
    }
    
    open func yp_navigationBackgroundColor() -> UIColor! {
        return UIColor(hex: 0xFFFFFF)
    }

    open func yp_navigationBackgroundImage(withIdentifier identifier: AutoreleasingUnsafeMutablePointer<NSString?>!) -> UIImage! {
        return nil
    }
}
